const EventEmitter = require('events');
const util= require('util');

function MyEmitter() {
    EventEmitter.call(this);
}
util.inherits(MyEmitter, EventEmitter);

const myEmitter = new MyEmitter();

var callbackA = () => {
    console.log('A');
    myEmitter.removeListener('event', callbackB);
};

var callbackB = () => {
    console.log('B');
};

myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);

// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');

// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
